package org.dut.community.util;

public class RedisKeyUtil {
    private static final String SPLIT = ":";
    private static final String PREFIX_ENTITY_LIKE = "like:entity";
    private static final String PREFIX_USER_LIKE = "like:user";
    private static final String PREFIX_FOLLOWEE = "followee";
    private static final String PREFIX_FOLLOWER = "follower";
    private static final String PREFIX_KAPTCHA = "kaptcha";
    private static final String PREFIX_TICKET = "ticket";
    private static final String PREFIX_USER = "user";
    private static final String PREFIX_FORGET = "forget:email";
    private static final String PREFIX_LIKE_POST = "like:post";
    private static final String PREFIX_POST_READ = "post:read";
    private static final String PREFIX_UV = "uv"; // 独立访客
    private static final String PREFIX_DAU = "dau"; // 日活跃用户
    private static final String PREFIX_POST = "post";
    private static final String PREFIX_POST_UNREAD = "post:unread"; // 未读

    // 实体点赞列表(某个实体收到的赞的用户集合)
    // like:entity:entityType:entityId
    public static String getEntityLikeKey(int entityType, int entityId) {
        return PREFIX_ENTITY_LIKE + SPLIT + entityType + SPLIT + entityId;
    }

    // 用户收到的点赞
    // like:user:userId
    public static String getUserLikeKey(int userId) {
        return PREFIX_USER_LIKE + SPLIT + userId;
    }

    // userId关注的followee的集合
    // followee:userId:entityType
    public static String getFolloweeKey(int userId, int entityType) {
        return PREFIX_FOLLOWEE + SPLIT + userId + SPLIT + entityType;
    }

    // 某个实体拥有的follower(粉丝)的集合
    // follower:entityType:entityId
    public static String getFollowerKey(int entityType,int entityId) {
        return PREFIX_FOLLOWER + SPLIT + entityType + SPLIT + entityId;
    }

    // 验证码
    // kaptcha:owner
    public static String getKaptchaKey(String owner) {
        return PREFIX_KAPTCHA + SPLIT + owner;
    }

    // 登录凭证
    // ticket:ticket
    public static String getTicketKey(String ticket) {
        return PREFIX_TICKET + SPLIT + ticket;
    }

    // 用户
    // user:id
    public static String getUserKey(int userId) {
        return PREFIX_USER + SPLIT + userId;
    }

    // 忘记密码：发送验证码
    // forget:email:***@***.com
    public static String getForgetKey(String email) {
        return PREFIX_FORGET + SPLIT + email;
    }

    // 某个用户赞了的帖子集合
    // like:post:userId ——> Zset(post,likeTime)
    public static String getLikePostKey(int userId) {
        return PREFIX_LIKE_POST + SPLIT + userId;
    }


    // 统计帖子阅读量
    // post:read:postId -> int
    public static String getPostReadKey(int postId){
        return PREFIX_POST_READ + SPLIT + postId;
    }

    // 单日uv
    public static String getUVKey(String date){
        return PREFIX_UV + SPLIT + date;
    }

    // 区间uv
    public static String getUVKey(String startDate, String endDate){
        return PREFIX_UV + SPLIT + startDate + SPLIT + endDate;
    }

    // 单日dau
    public static String getDAUKey(String date){
        return PREFIX_DAU + SPLIT + date;
    }

    // 区间dau
    public static String getDAUKey(String startDate, String endDate){
        return PREFIX_DAU + SPLIT + startDate + SPLIT + endDate;
    }

    // 统计帖子分数：存分数产生变化的帖子，不需要传参
    public static String getPostScoreKey(){
        return PREFIX_POST + SPLIT + "score";
    }

    // 用户关注、未读的帖子
    // post:unread:userId
    public static String getFolloweePostUnreadKey(int userId) {
        return PREFIX_POST_UNREAD + SPLIT + userId;
    }


}
